import request from '@/core/request/index'

// 获取用户信息
export const fetchUserInfo = (data) => {
  return request({
    url: '/user/getUserInfo',
    method: 'POST',
    data
  })
}

// 绑定图片地址跟账号
export const bind = (account, onlyId, url) => {
  return request({
    url: '/user/bindAccount',
    method: 'POST',
    data: {
      account,
      onlyId,
      url
    }
  })
}

// 修改密码
export const changePassword = (id, newPassword) => {
  return request({
    url: '/user/changePassword',
    method: 'POST',
    data: {
      id,
      newPassword
    }
  })
}

// 修改姓名
export const changeName = (name, id) => {
  return request({
    url: '/user/changeName',
    method: 'POST',
    data: {
      name,
      id
    }
  })
}

// 修改性别
export const changeSex = (gender, id) => {
  return request({
    url: '/user/changeSex',
    method: 'POST',
    data: {
      gender,
      id
    }
  })
}

// 修改邮箱
export const changeEmail = (email, id) => {
  return request({
    url: '/user/changeEmail',
    method: 'POST',
    data: {
      email,
      id
    }
  })
}

// ----------------------------------------用户管理
// 添加管理员
export const createAdmin = data => {
  const {
    account,
    ...identity
  } = data
  return request({
    url: '/user/createAdmin',
    method: 'POST',
    data: {
      account,
      ...identity
    }
  })
}

// 获取管理员列表
export const getAdminList = identity => {
  return request({
    url: '/user/getAdminList',
    method: 'POST',
    data: {
      identity
    }
  })
}

// 编辑管理员账号信息
export const editAdmin = data => {
  return request({
    url: '/user/editAdmin',
    method: 'POST',
    data,
  })
}

// 对管理员取消赋权
export const changeIdentityToUser = id => {
  return request({
    url: '/user/changeIdentityToUser',
    method: 'POST',
    data: {
      id
    }
  })
}

// 对用户进行赋权
export const changeIdentityToAdmin = (id, identity) => {
  return request({
    url: '/user/changeIdentityToAdmin',
    method: 'POST',
    data: {
      id,
      identity
    }
  })
}

// 通过账号对用户搜索
export const searchUser = (account, identity) => {
  return request({
    url: '/user/searchUser',
    method: 'POST',
    data: {
      account,
      identity
    }
  })
}

// 通过部门对用户搜索
export const searchDepartment = department => {
  return request({
    url: '/user/searchUserByDepartment',
    method: 'POST',
    data: {
      department
    }
  })
}


// 冻结用户
export const banUser = id => {
  return request({
    url: '/user/banUser',
    method: 'POST',
    data: {
      id
    }
  })
}

// 解冻用户
export const hotUser = id => {
  return request({
    url: '/user/hotUser',
    method: 'POST',
    data: {
      id
    }
  })
}

// 获取冻结用户列表
export const getBanList = () => {
  return request({
    url: '/user/getBanList',
    method: 'POST',
  })
}

// 删除用户  deleteUser
export const deleteUser = (id, account) => {
  return request({
    url: '/user/deleteUser',
    method: 'POST',
    data: {
      id,
      account
    }
  })
}

// 获取对应身份的一个总人数
export const getAdminListLength = identity => {
  return request({
    url: '/user/getAdminListLength',
    method: 'POST',
    data: {
      identity
    }
  })
}

// 监听换页返回数据
export const returnListData = (pager, identity) => {
  return request({
    url: '/user/returnListData',
    method: 'POST',
    data: {
      pager,
      identity
    }
  })
}
